package com.example.controller;

import com.example.dto.Result;
import com.example.entity.Collection;
import com.example.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/collection")
@Api("对收藏表的操作")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    @RequestMapping(value = "/getMyCollectionBySentenceId", method = RequestMethod.POST)
    @ApiOperation(value = "获取当前用户的收藏", notes = "发送用户id给服务器，标识为：userId")
    public Result<List<Collection>> getMyCollectionBySentenceId(@RequestParam("userId") String userId){
        Result<List<Collection>> result = new Result<>();
        List<Collection> list = collectionService.getCollectionsByUserId(userId).get("sentenceCollection");
        return result.ok("当前用户的所有句子收藏", list);
    }

    @RequestMapping(value = "/getMyCollectionByTopicId", method = RequestMethod.POST)
    @ApiOperation(value = "获取当前用户的收藏", notes = "发送用户id给服务器，标识为：userId")
    public Result<List<Collection>> getMyCollectionByTopicId(@RequestParam("userId") String userId){
        Result<List<Collection>> result = new Result<>();
        List<Collection> list = collectionService.getCollectionsByUserId(userId).get("topicCollection");
        return result.ok("当前用户的所有主题收藏", list);
    }

    @RequestMapping(value = "/addCollection", method = RequestMethod.POST)
    @ApiOperation(value = "添加句子或主题收藏", notes = "发送参数：用户id（userId），句子id（sentenceId），主题id（topicId）\n" +
            "如果添加句子，则主题id为：0；如果添加主题，则句子id为：0")
    public void addCollection(@RequestParam("userId") String userId,
                              @RequestParam("sentenceId") String sentenceId, @RequestParam("topicId") String topicId) {
        collectionService.addCollection(userId, sentenceId, topicId);
    }

    @RequestMapping(value = "/removeCollection", method = RequestMethod.POST)
    @ApiOperation(value = "用户删除收藏记录", notes = "发送参数：用户id（userId），句子id（sentenceId），主题id（topicId）\n" +
            "如果删除句子，则主题id为：0；如果删除主题，则句子id为：0")
    public void removeCollection(@RequestParam("userId") String userId,
                                 @RequestParam("sentenceId") String sentenceId, @RequestParam("topicId") String topicId){
        collectionService.removeCollection(userId, sentenceId, topicId);
    }

}
